<!DOCTYPE html>
<!--
Copyright (c) 2013 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="/tracing/core/test_utils.html">
<link rel="import" href="/tracing/extras/importer/linux_perf/ftrace_importer.html">

<script>
'use strict';

tr.b.unittest.testSuite(function() {
  test('kernelFunctionParser', function() {
    const lines = [
      'Binder_2-127  ( 127) [001] ....  3431.906759: graph_ent: func=sys_write',
      'Binder_2-127  ( 127) [001] ....  3431.906769: graph_ret: func=sys_write',
      'Binder_2-127  ( 127) [001] ....  3431.906785: graph_ent: func=sys_write',
      'Binder_2-127  ( 127) [001] ...1  3431.906798: tracing_mark_write: B|' +
          '127|dequeueBuffer',
      'Binder_2-127  ( 127) [001] ....  3431.906802: graph_ret: func=sys_write',
      'Binder_2-127  ( 127) [001] ....  3431.906842: graph_ent: func=sys_write',
      'Binder_2-127  ( 127) [001] ...1  3431.906849: tracing_mark_write: E',
      'Binder_2-127  ( 127) [001] ....  3431.906853: graph_ret: func=sys_write',
      'Binder_2-127  ( 127) [001] ....  3431.906896: graph_ent: func=sys_write',
      'Binder_2-127  ( 127) [001] ....  3431.906906: graph_ret: func=sys_write'
    ];
    const m = tr.c.TestUtils.newModelWithEvents([lines.join('\n')], {
      shiftWorldToZero: false
    });
    assert.isFalse(m.hasImportWarnings);

    const process = m.processes[127];
    assert.isDefined(process);

    const thread = process.threads[127];
    assert.isDefined(thread);

    const slices = thread.sliceGroup.slices;
    assert.strictEqual(thread.sliceGroup.length, 7);

    // Slice 0 is an un-split sys_write
    assert.strictEqual(slices[0].title, 'sys_write');

    // Slices 1 & 3 are a split sys_write
    assert.strictEqual(slices[1].title, 'sys_write');
    assert.strictEqual(slices[2].title, 'dequeueBuffer');
    assert.strictEqual(slices[3].title, 'sys_write (cont.)');

    // Slices 4 & 5 are a split sys_write with the dequeueBuffer in between
    assert.strictEqual(slices[4].title, 'sys_write');
    assert.strictEqual(slices[5].title, 'sys_write (cont.)');

    // Slice 6 is another un-split sys_write
    assert.strictEqual(slices[6].title, 'sys_write');
  });
});
</script>

